﻿using System;
using WebMatrix.WebData;

/// <summary>
/// Summary description for SiteSecurity
/// </summary>
public class SiteSecurity
{
    public SiteSecurity()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public static void RequireAuthenticatedUser()
    {
        WebSecurity.RequireAuthenticatedUser();
    }

    public static void InitializeDatabaseConnection()
    {
        WebSecurity.InitializeDatabaseConnection(DBObject.DatabaseName, "UserProfile", "UserId", "Email", true);
    }

    public static bool IsAuthenticated
    {
        get
        {
            return WebSecurity.IsAuthenticated;
        }
    }

    public static string CurrentUserName
    {
        get
        {
            return WebSecurity.CurrentUserName;
        }
    }

    public static bool ChangePassword(string userName, string currentPassword, string newPassword)
    {
        return WebSecurity.ChangePassword(userName, currentPassword, newPassword);
    }

    public static bool ChangePassword(string currentPassword, string newPassword)
    {
        return WebSecurity.ChangePassword(SiteSecurity.CurrentUserName, currentPassword, newPassword);
    }

    public static void Logout()
    {
        WebSecurity.Logout();
    }

    public static bool ConfirmAccount(string accountConfirmationToken)
    {
        return WebSecurity.ConfirmAccount(accountConfirmationToken);
    }

    public static int GetUserId(string userName)
    {
        return WebSecurity.GetUserId(userName);
    }

    /// <summary>
    /// Override: Return Current logged In user Id
    /// </summary>
    /// <returns></returns>
    public static int GetUserId()
    {
        return WebSecurity.GetUserId(SiteSecurity.CurrentUserName);
    }

    public static bool IsConfirmed(string userName)
    {
        return WebSecurity.IsConfirmed(userName);
    }

    public static string GeneratePasswordResetToken(string userName, int tokenExpirationInMinutesFromNow = 1440)
    {
        return WebSecurity.GeneratePasswordResetToken(userName);
    }

    public static bool UserExists(string userName)
    {
        return WebSecurity.UserExists(userName);
    }

    public static int GetPasswordFailuresSinceLastSuccess(string userName)
    {
        return WebSecurity.GetPasswordFailuresSinceLastSuccess(userName);
    }

    public static DateTime GetLastPasswordFailureDate(string userName)
    {
        return WebSecurity.GetLastPasswordFailureDate(userName);
    }

    public static bool Login(string userName, string password, bool persistCookie = false)
    {
        return WebSecurity.Login(userName, password, persistCookie);
    }

    public static bool ResetPassword(string passwordResetToken, string newPassword)
    {
        return WebSecurity.ResetPassword(passwordResetToken, newPassword);
    }

    public static string CreateAccount(string userName, string password, bool requireConfirmationToken = false)
    {
        return WebSecurity.CreateAccount(userName, password, requireConfirmationToken);
    }
}